package com.hzsd.zengbanyi.biaodan_text.Actrivity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;

import com.hzsd.zengbanyi.biaodan_text.BaseActivity;
import com.hzsd.zengbanyi.biaodan_text.MyAdapter.FragmentAdapterAnalysis;
import com.hzsd.zengbanyi.biaodan_text.R;
import com.hzsd.zengbanyi.biaodan_text.fragment.OriginalRecordFragment;
import com.hzsd.zengbanyi.biaodan_text.fragment.ProjectAnalysisFragment;
import com.viewpagerindicator.TabPageIndicator;

import java.util.ArrayList;
import java.util.List;

import hzst.android.view.TabsPager;


public class AnalysisActivity extends BaseActivity implements OnClickListener {
	private RelativeLayout rl_return;
	private TabPageIndicator pageIndicator;
//	private TabLayout tabLayout;
	private ViewPager viewPager;
	private FragmentAdapterAnalysis adapterAnalysis;
	private List<Fragment> fragments;
	private String[] title = {"项目分析","原始记录单"};
	private ProjectAnalysisFragment projectAnalysisFragment;
	private OriginalRecordFragment originalRecordFragment;
	private String task_id,task_scene_id,item_id,sample_code_btn;
	TabsPager tabsPager;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_analysis);
		initBaseData();
		initView();
		init();
		initEvents();
	}
//aaa
	private void initBaseData() {
		Bundle bundle = getIntent().getExtras();
		task_id = bundle.getString("task_id");
		task_scene_id = bundle.getString("task_scene_id");
		item_id = bundle.getString("item_id");
		sample_code_btn = bundle.getString("sample_code_btn");
	}

	private void initView() {
		rl_return = (RelativeLayout) findViewById(R.id.rl_return);
		viewPager = (ViewPager) findViewById(R.id.vp_viewpager);
		tabsPager = (TabsPager) findViewById(R.id.tp_TabsPager);
//		tabLayout = (TabLayout) findViewById(R.id.tl_tab);
		pageIndicator = (TabPageIndicator) findViewById(R.id.tpi_TabPageIndicator);
	}

	private void init() {
		fragments = new  ArrayList<Fragment>();;
		projectAnalysisFragment = new ProjectAnalysisFragment();
		originalRecordFragment = new OriginalRecordFragment();
		
		Bundle bundle = new Bundle();
		bundle.putString("task_id", task_id);
		bundle.putString("task_scene_id", task_scene_id);
		bundle.putString("item_id", item_id);
		bundle.putString("sample_code_btn", sample_code_btn);
		
		projectAnalysisFragment.setArguments(bundle);
		originalRecordFragment.setArguments(bundle);
		
		fragments.add(projectAnalysisFragment);
		fragments.add(originalRecordFragment);
		
//		adapterAnalysis = new FragmentAdapterAnalysis(getSupportFragmentManager(), fragments, title);
//		viewPager.setAdapter(adapterAnalysis);
//
//		pageIndicator.setViewPager(viewPager);

		tabsPager.setFragmentList(fragments);
		tabsPager.setTabNames(title);
		tabsPager.setTextColorSelected(R.color.blue_butoon);
		tabsPager.showView();


		
//		viewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
//		tabLayout.setTabMode(TabLayout.MODE_FIXED);
//		tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.blue));
//		tabLayout.setTabTextColors(getResources().getColor(R.color.gray_text), getResources().getColor(R.color.blue));
//		tabLayout.setupWithViewPager(viewPager);
	}
	
	private void initEvents() {
		rl_return.setOnClickListener(this);
		
		pageIndicator.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.rl_return:
			finish();
			break;

		default:
			break;
		}

	}

}
